/**
 * 
 */
package com.shark.app.common.validate.validator;

import java.util.regex.Pattern;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;

import com.shark.app.common.validate.anno.HttpUrl;

/**
 * @author lenovo
 * @description
 * @date 2016年8月17日
 */
public class HttpUrlValidator implements ConstraintValidator<HttpUrl, String> {

	private String httpUrlReg = "(http|ftp|https):\\/\\/[\\w\\-_]+(\\.[\\w\\-_]+)+([\\w\\-\\.,@?^=%&amp;:/~\\+#]*[\\w\\-\\@?^=%&amp;/~\\+#])?";// 表示http的正则表达式
	private Pattern httpUrlPattern = Pattern.compile(httpUrlReg);

	@Override
	public void initialize(HttpUrl constraintAnnotation) {
		// TODO Auto-generated method stub

	}

	@Override
	public boolean isValid(String value, ConstraintValidatorContext context) {
		if (value == null)
			return true;
		return httpUrlPattern.matcher(value.toString()).matches();
	}

}
